var Enhancements = {
	Collection: function(caster) {
		var me = this;
		this.Caster = caster;

		this.Items = {};

		this.Add = function(name, params) {
			params = params || {};
			var item = me.Items[name];
			params.caster = me.Caster;
			if ( item ) {
				item.AddStacks(params);
				return true;
			}

			params = $.extend(Enhancements.Params[name], params)

			var enhancement = new Enhancements.Enhancement(params);
			me.Items[name] = enhancement;
			Log({type: 'Enhancements.Collection.Add', enhancement: enhancement});
			return true;
		};

		this.HasAny = function(name) {
			if ( me.Items[name] ) return true;
			return false;
		};

		this.RemoveStacks = function(params) {
			var item = me.Items[params.name];
			var stacks = item.RemoveStacks(params);
			if ( !stacks ) {
				me.Remove(params.name);
			}
			return stacks;
		};

		this.Remove = function(name) {
			delete(me.Items[name]);
			Log({type: 'Enhancements.Collection.Remove', enhancement_name: name});
		};

		this.Stacks = function(name) {
			var item = me.Items[name];
			return ( item ) ? item.Stacks : 0;
		};
	},
	Enhancement: function(params) {
		var me = this;

		this.Id     = params.id;
		this.Name   = params.name;
		this.Caster = params.caster;

		this.Stacks         = params.stacks || 5;
		this.AddStackCount  = params.add_stack_count || this.Stacks;
		this.Damage         = params.Damage || null;
		this.Debuffs        = params.Debuffs || null;

		this.AddStacks = function(params) {
			this.Stacks += ( params && params.stacks ) ? params.stacks : this.AddStackCount;
			Log({type: 'Enhancements.Enhancement.AddStacks', enhancement: me, params: params});
		};

		this.RemoveStacks = function(params) {
			this.Stacks -= ( params && params.stacks ) ? params.stacks : 1;
			Log({type: 'Enhancements.Enhancement.RemoveStacks', enhancement: me, params: params});
			return this.Stacks;
		};

		/*this.OnDamage = function(caster, target) {
			for ( var k in debuffs ) {
				var debuff = debuffs[k];
				var oroll = caster.OffenseRoll(k, debuff.MaxChance);
				var droll = target.DefenseRoll(k);
				if ( oroll > droll ) {
					target.Debuff(caster, target, k);
				}
			}
		};*/
	},
	Params: {
		focus: {
			id: 'focus',
			name: 'Focus',
			damage: 1.5
		},
		fire: {
			id: 'fire',
			name: 'Fire',
			damage: 1.1,
			debuffs: {
				'ignite': {
					MaxChance: .1
				}
			}
		},
		wind: {
			id: 'wind',
			name: 'Wind',
			damage: 1.1,
			range: 1.5
		}
	}
};
